<template>
  <div class="container">
    <import-item :delRow="delRow" :excel-address="excelAddress" :table-column="tableColumn" :api-url="apiUrl"
      :api-param="apiParam" :validate-data="validateData" :uni-key="uniKey" :handle-data="handleData"
      @success="success">
    </import-item>
  </div>
</template>

<script>
import ImportItem from '@/components/Import'
import { d_targetType } from '@/utils/dicts.js'
export default {
  name: 'BidEnsureImport',
  components: {
    ImportItem
  },
  props: {

  },
  data () {
    return {
      // 删除行
      delRow: 2,
      // api地址
      apiUrl: '/api/ac/maintain/maintainSubjectSubService/addImportData',
      // 表格表头
      tableColumn: [
        { value: 'parent_id', label: '标的ID' },
        { value: 'id', label: '指标项ID' },
        { value: 'target_index_params', label: '指标项' },
        { value: 'target_desc_params', label: '指标描述' },
        { value: 'target_require_params', label: '指标要求' },
        { value: 'service_time_params', label: '服务时间' },
        { value: 'service_method_params', label: '服务方式' },
        { value: 'service_result_params', label: '交付成果' },
        { value: 'del_flag', label: '是否删除' }
      ],
      // excel地址
      excelAddress: '/static/excel/target.xlsx',
      // 预前校验数据重复的key
      uniKey: '',
      // 问题单元格的颜色配置
      troubleColor: {
        cellColor: '#42b883',
        cellBgColor: '#cbe4df',
        cellRepeatColor: '#eee',
        cellRepeatBgColor: '#90c3f6'
      },
      // 格式校验方法
      validateData: this.validateDataMethos,
      // 数据处理方法
      handleData: this.handleDataAction,
      d_targetType: d_targetType,
    }
  },
  created () {

  },
  mounted () {
  },
  methods: {
    validateDataMethos (item, error, tName) {
      if (!item.parent_id) {
        item.parent_id = '标的不能为空'
        item.cellClassName.parent_id = tName
        error = true
      }
      if (!item.target_index_params) {
        item.target_index_params = '指标项不能为空'
        item.cellClassName.target_index_params = tName
        error = true
      }
      if (!item.target_desc_params) {
        item.target_desc_params = '指标描述不能为空'
        item.cellClassName.target_desc_params = tName
        error = true
      }
      if (!item.target_require_params) {
        item.target_require_params = '指标要求不能为空'
        item.cellClassName.target_require_params = tName
        error = true
      }
      if (!item.service_time_params) {
        item.service_time_params = '服务时间不能为空'
        item.cellClassName.service_time_params = tName
        error = true
      }
      if (!item.service_method_params) {
        item.service_method_params = '服务方式不能为空'
        item.cellClassName.service_method_params = tName
        error = true
      } else {
        let type = item.service_method_params.trim()
        const type1 = '现场远程现场和远程'
        if (type.length !== 2 && type.length !== 5) {
          item.service_method_params = '服务方式类型错误'
          item.cellClassName.service_method_params = tName
          error = true
        }
        if (type1.indexOf(type) === -1) {
          item.service_method_params = '服务方式类型错误'
          item.cellClassName.service_method_params = tName
          error = true
        }
      }

      if (!item.service_result_params) {
        item.service_result_params = '交付成果不能为空'
        item.cellClassName.service_result_params = tName
        error = true
      }
      if (!item.del_flag) {
        item.del_flag = '是否删除不能为空'
        item.cellClassName.del_flag = tName
        error = true
      } else {
        let type = item.del_flag.trim()
        const type1 = '是否'
        if (type1.indexOf(type) === -1) {
          item.del_flag = '是否删除类型错误'
          item.cellClassName.del_flag = tName
          error = true
        }
      }
      return error
    },
    handleDataAction (item) {
      if (item.service_method_params) {
        let type = item.service_method_params.trim()
        for (let i of this.d_targetType) {
          if (i.label === type) {
            item.service_method_params = i.value
            break
          }
        }
      }
      if (item.del_flag) {
        let type = item.del_flag.trim()
        if (type === '是') {
          item.del_flag = '1'
        } else if (type === '否') {
          item.del_flag = '0'
        }
      }
      return item
    },
    success () {
      this.$emit('cancel');
    }
  },
  computed: {
    apiParam () {
      return {}
    }
  }
}
</script>
<style lang='scss' scoped>
</style>
